package com.sunfeng.netty.atguigu2.nio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

public class NIOClient1 {
    public static void main(String[] args) throws IOException {
        SocketChannel socketChannel = SocketChannel.open();
        socketChannel.configureBlocking(false);

        boolean connect = socketChannel.connect(new InetSocketAddress("127.0.0.1", 8080));

        if(!connect){
            while (!socketChannel.finishConnect()){
                System.out.println("连接需要时间，客户端不会阻塞继续进行其他工作");
            }
        }
        //...如果连接成功，就发送数据
        String str = "hello, 尚硅谷~";

        ByteBuffer byteBuffer = ByteBuffer.wrap(str.getBytes());

        socketChannel.write(byteBuffer);
        System.in.read();


    }
}
